package com.huawei.xme.ch02.t13;

import com.huawei.xme.utils.BigDecimalUtil;

import java.math.BigDecimal;
import java.util.Arrays;

/**
 * @author 黄后林
 * @date 2022-10-28 15:35:59
 * @note 程序员是用代码喂出来的
 */
public class Task01 {

    public static void main(String[] args) {

        double[] array={9.8,12,45,67,23,1.98,2.55,45};

        //1 max
        Arrays.sort(array);
        System.out.println(array);

        int len = array.length;

        double max = array[len-1];
        System.out.println(max);

        //2 min
        double min =array[0];
        System.out.println(min);

        //3 avg

        BigDecimal avg =getAvg(array);
        System.out.println(avg);


    }

    private static BigDecimal getAvg(double[] array) {
        // 入参检测
        double sum=0;
        // 数组的长度
        int len = array.length;

        for (int i = 0; i < len; i++) {
            sum+=array[i];
        }
        double avg = sum/len;
        return BigDecimalUtil.getBigDecimal(avg,2);
    }


}
